'use strict';

var fs=require('fs');
var {sequelize}=require('../db');

function searchFiles(){
    var files=fs.readdirSync(__dirname);
    return files.filter(name=>{
        return name.endsWith('.js') && name !=='index.js';
    })
}

function registerModels(files){
    var obj={};
    files.forEach(name=>{
        var modelName=name.substring(0,name.length-3);
        obj[modelName]=require(__dirname+'/'+name);
    })

    return obj;
}


var files=searchFiles();
var obj=registerModels(files);

obj.sync=async ()=>{
    return sequelize.sync({force:true})
}

module.exports=obj;